package com.wang.tool.proxy;

import com.alibaba.fastjson.JSONObject;

import java.util.function.Function;

/**
 * 环绕切面
 *
 * @Author wangshaopeng
 * @Date 2021/1/31
 */
public abstract class AroundCut implements Cut {

    @Override
    public final Object invoke(FunctionProxy<Object, Object>.InvokeChain chain, Object param, JSONObject runCtx) {
        return around(p -> chain.chain(p, runCtx), param, runCtx);
    }


    /**
     * 环绕操作
     *
     * @param delegate 被代理的实现 非空
     * @param param    入参
     * @param runCtx   运行环境 非空
     * @return 返回值
     */
    protected abstract Object around(Function<Object, Object> delegate, Object param, JSONObject runCtx);


    @Override
    public final int level() {
        return 11;
    }
}
